{include file="news/header.tpl"}
  <script src="./static/public/jquery-1.11.0.min.js"></script>
  <script src="./static/public/jqueryui/jquery-ui.js"></script>

	<!-- start: Content -->
	{literal}
  <script>
  $(function() {
 
    $( "#goods_name" ).autocomplete({
      source: "./index.php?buy/api/?",
      minLength: 1,
    });
  });
  </script>
{/literal}			
						
			<div class="row-fluid">


<div class="box"><!-- Default panel contents -->

<div class="box-content" id="form1">
流水号 {$order.id}  下单时间:{$order.add_time|date_format:"%Y-%m-%d %H:%M"}<br>


<a href="javascript:pt({$order.id})" id="print" class="btn btn-default pull-right"><i class="icon-print">打印</i></a>


<table class="table table-bordered table-hover">
	<tr class=title>
		<th width="20%">商品名称</th>
		<th width="20%">属性快照</th>
		<th width="5%">单价</th>
		<th width="10%">一件数量</th>
		<th width="10%">订购件数</th>
		<th width="10%">合计数量</th>
		<th width="8%">小计</th>
	</tr>



   {foreach from=$goods item=l}
	<tr id="mx{$l.id}">
		<td>{$l.goods_name} <a href="javascript:del({$l.id})"><i class="icon-trash"></i></a></td>
		<td>
		{if $l.module>1}
		<input type="text" id="snapshot{$l.id}" onblur="snapshot({$l.id})" value="{if $l.snapshot==''}{$l.type}{else}{$l.snapshot}{/if}"></td>
		{else}
		{$l.snapshot}
		{/if}
		<td><input type="text" name="price" class="input-mini" title="{$l.id}" id="price{$l.id}" value="{$l.price}" onblur="save(this)"></td>
		<td><span id="num{$l.id}">{$l.num}</span>{$l.unit}</td>
		<td><input type="text" name="num" class="input-mini" title="{$l.id}" value="{$l.count}" onblur="save(this)"></td>
	  <td id="count{$l.id}">{$l.num*$l.count}</td>
	
		<td id="tmoney{$l.id}">{$l.total_money}</td>
	</tr>
	{/foreach}
	<tr id="append">
<td>
<input type="text" name="goods_name" id="goods_name" placeholder="请输入产品名称"></td>
<td></td>
<td></td>
<td></td>

<td><input type="text" name="count" class="input-mini" placeholder="件数">
</td>

<td></td>

<td>
<button onclick="add('{$order.orderno}')" class="btn btn-success">新增</button>

</td>
</tr>
	
	
	<tr>
	<th>总计</th>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td id="totalnum">{$order.num}</td>
	<td id="totalmoney">{$order.money}</td>
	</tr>
	<tr><th>备注</th><td colspan="6" >{$order.remark}</td></tr>
	
</table>



订单号: {$order.orderno}<br>
收货人: {$shr.real_name}  <br>
地　址: {$shr.area}  <br>
手　机: {$shr.mobile_phone}

<div id="log">
操作历史记录<br>
{foreach from=$log item=l}
{$l.add_time|wtime}  {$l.username} {$l.event}<br>
{/foreach}
</div>
</div>
</div>


</div>
{literal}
<script>



function pt(id){
	
  $("#append").remove();
  $("i").remove();
  $("#log").remove();
  $("#print").remove();
  $.post("./index.php?buyorderinfo/p",{orderid:id});
	window.print();
}

function snapshot(id){

	var shot=$("#snapshot"+id).val();
	$.post("./index.php?buyorderinfo/snapshot",{id:id,snapshot:shot});	
}

function del(id){
$.post("./index.php?buyorderinfo/remove",{id:id},function(data){
	
   if(data.status==true){
   $("#mx"+id).remove();
   var order=data.data;
   refresh(order.num,order.money);
 }else{
	   alert(data.message);

	 }},"json")	
}

function add(orderno){
var name=$("input[name='goods_name']").val();
var num=$("input[name='count']").val();
$.post("./index.php?buyorderinfo/add",{orderno:orderno,goods_name:name,num:num},function(data){

  if(data.status==true){
   var  d=data.data.goods;
   var order=data.data.order;
   var con="<tr id=\"mx"+d.id+"\"><td>"+d.goods_name+"<a href=\"javascript:del("+d.id+")\"><i class=\"icon-trash\"></i></a></td><td>"+d.type+"</td>";
   con=con+"<td><input  type=\"text\" name=\"price\" class=\"input-mini\" title=\""+d.id+"\" id=\"price"+d.id+"\" value=\""+d.price+"\" onblur=\"save(this)\"></td>";
   con=con+"<td id=\"num"+d.id+"\">"+d.num+"</td>";
   con=con+"<td><input type=\"text\" name=\"num\" class=\"input-mini\" title=\""+d.id+"\" value=\""+d.count+"\" onblur=\"save(this)\"></td>";
   con=con+"<td id=\"count"+d.id+"\">"+d.num*d.count+"</td><td id=\"tmoney"+d.id+"\">"+d.total_money+"</td></tr>";
    $("#append").before(con);
  refresh(order.num,order.money);
   }else{
	   alert(data.message);
	   }
	},"json")

}

function refresh(num,money){

$("#totalnum").html(num);
$("#totalmoney").html(money);
}

function save(obj){
var id=$(obj).attr("title");
var key=$(obj).attr("name");
var v=$(obj).val();

if(key=="num"){
	
 totalnum(id,v);
}

$.post("./index.php?buyorderinfo/save",{id:id,key:key,value:v},function(data){
  
	if(data.status==true){
		var g=data.data.goods;
    var order=data.data.order;
    $("#tmoney"+id).html(g.total_money);
    refresh(order.num,order.money);
    }else{
    alert(data.message);
     }
},"json")


}

function totalnum(id,num){
	var n=$("#num"+id).html();
	var t=n*num;
	$("#count"+id).html(t);
}
</script>
{/literal}



